package com.insis.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.insis.entity.TrainEntity;
import com.insis.service.TrainService;

import java.util.*;

@Controller
public class TrainController {
	
	@Autowired
	private TrainService trainService;
	
    @RequestMapping(value={"/getTrainName"}, method=RequestMethod.GET)
    @ResponseBody
    public List<String> getTrainName(HttpServletRequest request, ModelMap model) {
        List<String> carNames = trainService.getAllTrainName();
        model.put("carNames", carNames);
        return carNames;
    }
    
    @RequestMapping(value={"/getTrainInfo"}, method=RequestMethod.GET)
    @ResponseBody
    public List<TrainEntity> getTrainInfo(@RequestParam("carName") String carName, ModelMap model) {
        List<TrainEntity> trains = trainService.getInfoBytrainName(carName);
        model.put("trains", trains);
        return trains;
    }
}